package cn.kgc.fxy.smbms.service.impl;

import cn.kgc.fxy.smbms.entity.Provider;
import cn.kgc.fxy.smbms.mapper.ProviderMapper;
import cn.kgc.fxy.smbms.service.ProviderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ProviderServiceImpl implements ProviderService {
    @Resource
    private ProviderMapper providerMapper;
    @Override
    public List<Provider> findByproName() {
        List<Provider> providerList = this.providerMapper.selectByproName();
        return providerList;
    }

    @Override
    public PageInfo<Provider> findProvider(Provider condition, Integer pageNum, Integer pageSize) {
        if (pageNum==null){
            pageNum = 1;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<Provider> providerList = this.providerMapper.selectProvider(condition);
        PageInfo<Provider> providerPageInfo = new PageInfo<>(providerList);
        return providerPageInfo;
    }

    @Override
    public Provider findView(Long proId) {
        Provider provider = this.providerMapper.selectView(proId);
        return provider;
    }

    @Override
    public void addProvider(Provider provider) {
        providerMapper.insertProvider(provider);
    }

    @Override
    public Integer findProviderCount(String proCode) {
        Integer findProviderCount = providerMapper.selectProviderCount(proCode);
        return findProviderCount;
    }

    @Override
    public void modifyProvider(Provider provider) {
        providerMapper.updateProvider(provider);
    }

    @Override
    public void removeProvider(Long proId) {
        providerMapper.deleteProvider(proId);
    }
}
